<?php
$txt=file_get_contents('php://input');
logfile($txt,'fry_check_data');
include_once('/var/www/html/new/d/module/api/function.class.php');
include('/var/www/html/new/d/module/api/FuRongYuan/furongyuan.class.php');

$PFT_infunction = new AllFunction();

if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}

$data = json_decode($_REQUEST['data'],true);
$remoOrder = 'fry_'.$data['param']['order_num'];
$pft_order_xml = $PFT_infunction->Select_REMOorder($remoOrder);
$UUlid = (string)$pft_order_xml->Rec->UUlid;

if(empty($UUlid)){
	echo '{"code":"0001","msg":"未找到订单"}';
	exit;
}
$fry = new FuRongYuan($UUlid);
$check_sign =$fry->sign($data['param']);
if($data['sign'] == $check_sign){
	$UUcode = (string)$pft_order_xml->Rec->UUcode;
	$UUsalerid = (string)$pft_order_xml->Rec->UUsalerid;
	$UUordernum  = (string)$pft_order_xml->Rec->UUordernum;
	$chkIns = 499;
	if((string)$pft_order_xml->Rec->UUstatus==2) $chkIns = 498;
	$actiontime = date('Y-m-d H:i:s',$data['param']['timestamp']);
	
	$terminal = $PFT_infunction->Unified_Check_IN($UUsalerid,$UUcode,$actiontime,$chkIns);
	if($terminal == 100){
		logfile($UUordernum."|".$terminal,'fry_check_success');
		$repCode = "0000";
		$repMsg = '验证成功';
	}else{
		logfile($UUordernum."|".$terminal,'fry_check_fail');
		$repCode = $terminal;
		$repMsg = "验证失败";
	}
}else{
	$code = "0004";
	$msg = "签名不通过";
}
echo '{"code":"'.$code.'","msg":"'.$msg.'"}';

function logfile($txt,$path){
	$fp = fopen('/var/www/html/new/d/logs/api/FuRongYuan/'.date('Y-m-d').$path.'.txt',"a");
	flock($fp, LOCK_EX) ;
	fwrite($fp,date('Y-m-d H:i:s').'|'.$txt."\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}
?>